package org.spider.s8;

import java.util.Map;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import jodd.http.HttpBrowser;
import jodd.http.HttpRequest;
import jodd.jerry.Jerry;
import jodd.jerry.JerryFormHandler;

public class Sex8Index {
	public void a() {
		final HttpBrowser browser = new HttpBrowser();

	    HttpRequest request = HttpRequest.get("http://sisqq.com/forum.html");
	    browser.sendRequest(request);

	    String page = browser.getPage();
	    Jerry doc = Jerry.jerry(page);

	    // process login form
	    doc.form("#lsform", new JerryFormHandler() {
	        public void onForm(Jerry form, Map<String, String[]> parameters) {

	            String formAction = form.attr("action");
	            HttpRequest loginRequest = HttpRequest.post(formAction);

	            for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
	                String[] values = entry.getValue();
	                String name = entry.getKey();

	                for (String value : values) {
	                    loginRequest.form(name, value);
	                }
	            }
	            Digester md5 = new Digester(DigestAlgorithm.MD5);
	            // overwrite form parameters
	            loginRequest.form("username", "onenpc", true);
	            loginRequest.form("password", md5.digestHex("and9527"), true);
	            loginRequest.form("quickforward", "yes", true);
	            loginRequest.form("handlekey", "ls", true);
	            loginRequest.form("sectouchpoint", "0", true);
	            loginRequest.form("referer", "portal.html", true);
	            browser.sendRequest(loginRequest);
	        }
	    });

	    // this is your personal page:
	    System.out.println("内容:"+browser.getPage());
	    String bodyText = browser.sendRequest(HttpRequest.get("http://sisqq.com/forum-96-1.html")).getHttpRequest().bodyText();
	    System.out.println("正文:"+bodyText);
	}
	
	public static void main(String[] args) {
		new Sex8Index().a();
	}
}
